package com.club.football.controller;

import com.club.football.dto.CoachSaveDto;
import com.club.football.dto.PageDto;
import com.club.football.entity.Coach;
import com.club.football.req.CoachPageReq;
import com.club.football.service.CoachService;
import com.club.football.utils.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static com.club.football.common.CommonConstants.DEL_OK_MSG;
import static com.club.football.common.CommonConstants.GET_INFO_OK;

/**
 * 教练Controller
 *
 * @author 1
 * @date 2023/12/28
 */
@RestController
@RequestMapping("/coach")
public class CoachController {
    @Resource
    private CoachService coachService;

    /**
     * 教练列表
     *
     * @return {@link R}
     */
    @GetMapping("/page")
    public R<PageDto<Coach>> page(PageDto<Coach> pageDto, CoachPageReq coachPageReq) {
        return coachService.coachPage(pageDto, coachPageReq);
    }

    /**
     * 保存
     *
     * @param saveDto 将数据保存到
     * @return {@link R}<{@link String}>
     */
    @PostMapping("/save")
    public R<String> save(@RequestBody @Valid CoachSaveDto saveDto) {
        return coachService.coachSave(saveDto);
    }

    /**
     * 信息
     *
     * @param id ID
     * @return {@link R}<{@link Coach}>
     */
    @GetMapping("/info/{id}")
    public R<Coach> info(@PathVariable Long id) {
        return R.ok(coachService.getById(id), GET_INFO_OK);
    }

    /**
     * 删除
     *
     * @param id ID
     * @return {@link R}<{@link String}>
     */
    @DeleteMapping("/remove/{id}")
    public R<String> remove(@PathVariable Long id) {
        coachService.removeById(id);
        return R.ok(DEL_OK_MSG);
    }

}
